/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tchepannou.limbe.web;

import com.tchepannou.util.MimeUtil;
import org.apache.commons.fileupload.FileItemStream;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 *
 * @author herve
 */
public class FilePartImpl 
    implements FilePart
{
    //-- Attribute
    private String _name;
    private byte[] _content;

    //-- Public
    public FilePartImpl (String name, byte[] content)
    {
        _name = name;
        _content = content;
    }


    //-- FilePart override
    @Override
    public String getName ()
    {
        return _name;
    }

    @Override
    public long getSize ()
    {
        return -1;
    }

    @Override
    public String getContentType ()
    {
        return MimeUtil.getInstance().getMimeTypeByFile(_name);
    }
    
    @Override
    public InputStream getInputStream ()
        throws IOException
    {
        return new ByteArrayInputStream(_content);
    }

}
